<?php
use yii\helpers\Html;
//use kartik\widgets\ActiveForm;
use yii\widgets\ActiveForm;
//use kartik\builder\Form;
use kartik\detail\DetailView;
use backend\models\Tags;
use backend\models\Country;
use yii\helpers\Url;
use backend\models\ProjectCategoriesDjr;
use yii\helpers\ArrayHelper;
use unclead\multipleinput\MultipleInput;
use mdm\widgets\TabularInput;
use kartik\widgets\Select2;
use kartik\widgets\DepDrop;

/*
//省市
$modelCountry = new Country();
$arr_provinces = $modelCountry->getProvinces();
$arr_cities = [];
if ($model->province) {
    $province = implode('', $modelCountry->getProvinces("id =" . $model->province));
    $arr_cities = $modelCountry->getProvinces("pid = $model->province");
} else {
    $province = '';
}
if ($model->city) {
    $city = implode('', $modelCountry->getProvinces("id=" . $model->city));
} else {
    $city = '';
}

//标签
$arr_tag = $model->tag;
$arr_tag_tag = [];
if ($model->tag && is_array($arr_tag) && count($arr_tag) > 0) {
    foreach ($arr_tag as $item) {
        $arr_tag_tag[] = Tags::findOne(['id' => $item])->title;
    }
    $tags = implode(',', $arr_tag_tag);
} else {
    $tags = '';
}

*/

$arr_categories_djr = ArrayHelper::map(ProjectCategoriesDjr::find()->where("id>33")->orderBy("order asc")->asArray()->all(), 'id', 'title');
$projectDjr->province = $model->province;
//$projectDjr->city = $model->city;
?>
<div class="container">
    <div class="project-single-form col-sm-9">
        <?php $form = ActiveForm::begin(['action' => ['publish', 'project_id' => $model->id], 'id' => 'form-publish',]); ?>
        <?= $form->field($projectDjr, 'title')->textInput(['value' => $model->title])->label(false) ?>
        <?= $form->field($projectMappingDjr, 'cid')->radioList($arr_categories_djr)->label(false) ?>
        <?= $form->field($projectDjr, 'province')->widget(Select2::className(), [
            'data' => Country::getCityList(),
            'size' => 'sm',
            'options' => ['placeholder' => '选择省份'],
            'pluginOptions' => [
                'allowClear' => true
            ],
        ])->label(false) ?>
        <?= $form->field($projectDjr, 'city')->widget(DepDrop::className(), [
            'type' => 2,
            'data' => Country::getCityList($model->province),

//            'select2Options'=>Country::getCityList($model->province),
            'options' => [
                'value' => $model->city,
                'allowClear' => true
            ],
            'pluginOptions' => [
                'depends' => ['projectdjr-province'],
                'placeholder' => '选择城市',
                'url' => Url::to(['/country/get-city', 'province' => 'projectdjr-province']),
            ],

        ])->label(false) ?>
        <?= $form->field($projectSingleDjrModel, 'project_tag_real')->checkboxList(Yii::$app->params['project_single_tag2djr']['real'])->label('房地产/不动产') ?>
        <?= $form->field($projectSingleDjrModel, 'project_tag_personal')->checkboxList(Yii::$app->params['project_single_tag2djr']['personal'])->label('动产') ?>
        <?= $form->field($projectSingleDjrModel, 'project_tag_intangible')->checkboxList(Yii::$app->params['project_single_tag2djr']['intangible'])->label('无形资产') ?>
        <?= $form->field($projectSingleDjrModel, 'project_tag_creditor')->checkboxList(Yii::$app->params['project_single_tag2djr']['creditor'])->label('债权') ?>

        <?= $form->field($projectSingleDjrModel, 'detail')->textarea(['value' => $model->detail]) ?>
        <?= $form->field($projectSingleDjrModel, 'asset')->textarea(['value' => $model->asset]) ?>
        <?= $form->field($projectDjr, 'recommend')->radioList(Yii::$app->params['is_recommend']) ?>
        <?= $form->field($projectSingleDjrModel, 'price_pre_evaluate')->textInput(['value' => $model->price_pre_evaluate])->label('评估总价（元）') ?>
        <?= $form->field($projectSingleDjrModel, 'evaluate_by')->textInput(['value' => $model->evaluate_by]) ?>
        <?= $form->field($projectMappingDjr, 'sell_price')->textInput(['value' => $model->price])->label('转让价格（元）') ?>
        <?php //echo $form->field($projectSingleDjrModel, 'project_tag'); ?>
        <hr>
        <?= $form->field($projectMappingDjr, 'thumbnail')->fileInput() ?>
        <hr>
        <div class="form-inline">
            <h4>涉及资产信息：</h4>
        </div>
        <table class="table">
            <thead>
            <tr>

                <th colspan="5" class="text-right">
                    <a id="btn-add-asset">
                        <button type="button" class="btn btn-info">
                            <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
                        </button>
                    </a>
                </th>
            </tr>
            </thead>
            <?=
            TabularInput::widget([
                'id' => 'asset-detail-grid',
                'allModels' => [$projectSingleAssetDjr,],
                'model' => $projectSingleAssetDjr,
                'tag' => 'tbody',
                'form' => $form,
                'itemOptions' => ['tag' => 'tr'],
                'itemView' => '_asset_item_detail',
                'clientOptions' => [
                    'btnAddSelector' => '#btn-add-asset',
                ]
            ]);
            ?>
        </table>
        <hr>
        <table class="table">
            <thead>
            <tr>
                <th colspan="3" class="text-right">
                    <a id="btn-add">
                        <button type="button" class="btn btn-info">
                            <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
                        </button>
                    </a>
                </th>
            </tr>
            </thead>
            <?=
            TabularInput::widget([
                'id' => 'detail-grid',
                'allModels' => [$projectFileDjr,],
                'model' => $projectFileDjr,
                'tag' => 'tbody',
                'form' => $form,
                'itemOptions' => ['tag' => 'tr'],
                'itemView' => '_file_item_detail',
                'clientOptions' => [
                    'btnAddSelector' => '#btn-add',
                ]
            ]);
            ?>
        </table>
        <hr>
        <div class="form-group">
            <?php echo Html::submitButton('提交', ['class' => 'btn btn-primary']);

            if (Yii::$app->controller->action->id == 'update') {
                echo '  <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>';
            } elseif (Yii::$app->controller->action->id == 'publish2djr') {
                echo '  <button type="button" class="btn btn-secondary" onclick="window.close();">关闭</button>';
            }

            ?>
        </div>
        <?php ActiveForm::end(); ?>

        <?php
        /*
        echo DetailView::widget([
            'model' => $model,
            'condensed' => true,
            'hover' => true,
            'mode' => 'edit',
            'panel' => [
                'heading' => '项目信息',
                'headingOptions' => ['template' => '{title}'],
                'type' => DetailView::TYPE_INFO,
                'footer' => '<span class="glyphicon glyphicon-pencil"></span>',
                'footerOptions' => ['class' => 'panel-heading', 'tag' => 'h4', 'template' => '{buttons}{title}']
            ],
            'formOptions' => ['options' => ['data-pjax' => true],],
            'hideIfEmpty' => false,//如果有空字段则隐藏
//            'buttons1' => '{update} {publish}',
            'buttons2' => '{reset} {save}',
//            'updateOptions' => ['label' => '<span class="btn btn-info">编辑</span>'],
//            'viewOptions' => ['label' => '<span class="btn btn-info">查看</span>'],
            'saveOptions' => ['label' => '<span class="btn btn-info">保存</span>'],
            'resetOptions' => ['label' => '<span class="btn btn-info">重置</span>'],
            'attributes' => [
                'title',
                [
                    'attribute' => 'category',
                    'type' => 'radioList',
                    'items' => Yii::$app->params['project_single_category'],
                    'value' => Yii::$app->params['project_single_category'][$model->category],
                    'valueColOptions' => ['class' => 'form-inline'],
//                'label' => "<span class='text-danger'>" . $model->getAttributeLabel('category') . "*</span>"
                ],
                [
                    'columns' => [
                        [
                            'attribute' => 'province',
                            'type' => DetailView::INPUT_SELECT2,
                            'value' => $province,
                            'widgetOptions' => [
                                'data' => $arr_provinces,
                                'options' => ['placeholder' => '选择省份 ...'],
                                'pluginOptions' => [
                                    'allowClear' => true
                                ]
                            ],
//                        'label' => "<span class='text-danger'>" . $model->getAttributeLabel('province') . "*</span>",
                            'valueColOptions' => ['style' => 'width:30%']
                        ],
                        [
                            'attribute' => 'city',
                            'type' => DetailView::INPUT_DEPDROP,
                            'widgetOptions' => [
                                'type' => 2,
                                'data' => count($arr_cities) > 0 ? $arr_cities : [],
                                'pluginOptions' => [
                                    'depends' => ['projectsingle-province'],
                                    'placeholder' => '选择城市...',
                                    'url' => Url::to(['/country/get-project-single-city',]),
                                ]
                            ],
                            'value' => $city,
                        ],
                    ],
                ],
                [
                    'attribute' => 'tag',
                    'type' => DetailView::INPUT_SELECT2,
                    'widgetOptions' => [
                        'data' => Tags::getAllTags(),
                        'options' => ['placeholder' => '选择标签'],
                        'pluginOptions' => [
                            'allowClear' => true,
                            'multiple' => true,
                        ]
                    ],
                    'value' => $tags,
                ],
                [
                    'attribute' => 'detail',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],
                [
                    'attribute' => 'asset',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],
                'address',
                'area',
                [
                    'attribute' => 'history',
                    'type' => DetailView::INPUT_TEXTAREA,
                    'options' => ['placeholder' => ''],
                ],
                [
                    'columns' => [
                        [
                            'attribute' => 'price', 'valueColOptions' => ['style' => 'width:15%'], 'format' => 'decimal',
//                        'label' => "<span class='text-danger'>" . $model->getAttributeLabel('price') . "*</span>",
                        ],
                        'price_per_area:decimal', 'price_pre_evaluate',
                    ],
                ],
                [
                    'attribute' => 'evaluate_by',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],
                [
                    'attribute' => 'contact',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],
            ]
        ]);
        */
        ?>
    </div>
</div>
